{% include 'admin/header.html' %}

<body>
  <div class="lyear-layout-web">
    <div class="lyear-layout-container">
      {% include 'admin/nav.html' %}

      <main class="lyear-layout-content">
        <div class="container-fluid">
          <!-- 提示信息 -->
          <div class="alert alert-info alert-dismissible fade show mb-4" role="alert">
            <i class="fas fa-info-circle mr-2"></i>
            当前页面为宿舍分配列表。请根据需要为用户分配宿舍。
            {% with messages = get_flashed_messages(with_categories=true) %}
              {% if messages %}
                <div class="mt-2">
                  {% for category, message in messages %}
                    <div class="alert alert-{{ category }} mb-2">
                      <strong>{{ message }}</strong>
                    </div>
                  {% endfor %}
                </div>
              {% endif %}
            {% endwith %}
          </div>

          <!-- 分配宿舍卡片 -->
          <div class="card shadow-lg mb-4 rounded-lg">
            <header class="card-header d-flex justify-content-between align-items-center">
              <h4 class="card-title mb-0 text-primary">
                <i class="fas fa-bed mr-2"></i> 分配宿舍
              </h4>
              <a href="{{ url_for('main.allocate_list') }}" class="btn btn-outline-primary btn-sm">
                <i class="fas fa-list"></i> 返回分配列表
              </a>
            </header>

            <div class="card-body">
              <form action="{{ url_for('main.allocate_dorm') }}" method="POST">
                <!-- 选择用户 -->
                <div class="form-group">
                  <label for="user_id" class="font-weight-bold">选择用户</label>
                  <select id="user_id" name="user_id" class="form-control" required>
                    <option value="" disabled selected>请选择用户</option>
                    {% for user in users %}
                    <option value="{{ user.id }}">{{ user.username }}</option>
                    {% endfor %}
                  </select>
                </div>

                <!-- 选择宿舍 -->
                <div class="form-group">
                  <label for="dorm_id" class="font-weight-bold">选择宿舍</label>
                  <select id="dorm_id" name="dorm_id" class="form-control" required>
                    <option value="" disabled selected>请选择宿舍</option>
                    {% for dorm in dorms %}
                    <option value="{{ dorm.id }}">
                      {{ dorm.name }} - {{ dorm.dorm_type.name }} ({{ dorm.bed_count }} 床位)
                    </option>
                    {% endfor %}
                  </select>
                </div>

                <!-- 入住时间 -->
                <div class="form-group">
                  <label for="check_in_time" class="font-weight-bold">入住时间</label>
                  <input type="datetime-local" id="check_in_time" name="check_in_time" class="form-control w-auto" required>
                </div>

                <!-- 提交按钮 -->
                <div class="form-group text-center mt-4">
                  <button type="submit" class="btn btn-primary btn-lg px-4 py-2">
                    <i class="fas fa-check-circle"></i> 分配宿舍
                  </button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>

{% include 'admin/footer.html' %}
</body>
